<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    /**
用Map减少查询判断的用时，出现过的值作为Map中的key，该值出现过的次数作为Map中的value

排序 + 贪心：能用做双倍的就双倍，不能的就让它往后找，找不到就不是双倍数组
     */
    var findOriginalArray = function (changed) {
      if (changed.length & 1) return []
      let res = []
      let map = new Map()
      changed.sort((a, b) => a - b)
      changed.forEach(element => {
        map.set(element, (map.get(element) || 0) + 1)
      })
      for (let i = 0; i < changed.length; i++) {
        let value = changed[i]
        if (!map.get(value)) continue;
        if (!map.get(value * 2)) return [];

        map.set(value, map.get(value) - 1)
        map.set(value * 2, map.get(value * 2) - 1)
        res.push(value)
      }
      return res
    };
    console.log(findOriginalArray(changed = [1, 3, 4, 2, 6, 8]))
  </script>
</body>

</html>